<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/8 0008
 * Time: 上午 9:33
 */
function checkUsername($username){
    if (!preg_match('/^[\w\x{4e00}-\x{9fa5}]{2,10}$/',$username)){
        return '用户名格式不符合要求';
    }
    return true;
}
function checkPassword($Password){
    if (!preg_match('/^\w{6,16}$/',$Password)){
        return '密码格式不符合要求';
    }
    return true;
}
function checkEmail($email){
    if (strlen($email) > 40){
        return '邮箱长度不合法';
    }elseif (!preg_match('/^[a-z0-9]+@([a-z0-9]+\.)+[a-z]{2.4}$/i',$email)){
        return '邮箱格式不符合要求';
    }
    return true;
}

require 'check_form.lib.php';
$data = array(
    'username' => '小明',
    'password' => '123456',
    'email' => 'xiaoming@123.com',
);
$validate = array(
    'username' => 'checkUsername',
    'password' => 'checkPassword',
    'email' => 'checkEmail',
);
$error = array();
foreach ($validate as $k=>$v){
    $result = $v($data[$k]);
    if ($result !== true){
        $error[]=$result; 
    }
}
if (empty($error)){
}else{
    require 'register_error_html.php'
}